﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook.Services;
using Facebook;
using System.Collections;
using Facebook.Contracts;
namespace WebApplication1
{
    public partial class QueryFb : System.Web.UI.Page
    {
        IFacebookService facebookservice;

        protected void Page_Load(object sender, EventArgs e)
        {

            facebookservice = this.Session["facebookservice"] as IFacebookService;

            this.btnQuery.Click += new EventHandler(btnQuery_Click);
        }

        void btnQuery_Click(object sender, EventArgs e)
        {
            dynamic queryResult = facebookservice.QueryGraph(this.txbQuery.Text, "json");

            ArrayList allResults = new ArrayList();
            
            foreach (object o in queryResult) 
            {
              allResults.AddRange((o as FacebookEntity).Properties);
            }

            pageListRes.DataSource = allResults;

            pageListRes.DataBind();
        }
    }
}